home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / dev / GUI / BGUI / demos / popwindow.c < prev    next >
C/C++ Source or Header  |  1994-09-11  |  11KB  |  206 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc popwindow.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6. **         $RCSfile: popwindow.c,v $
  7. **      Description: Simple demonstration of jumping to another screen.
  8. **        Copyright: (C) Copyright 1994 Jaba Development.
  9. **                   (C) Copyright 1994 Jan van den Baard.
  10. **                   All Rights Reserved.
  11. **
  12. **          $Author: jaba $
  13. **        $Revision: 1.1 $
  14. **            $Date: 1994/09/11 11:59:43 $
  15. **/
  16.  
  17. #include <libraries/bgui.h>
  18. #include <libraries/bgui_macros.h>
  19. #include <libraries/gadtools.h>
  20.  
  21. #include <clib/alib_protos.h>
  22.  
  23. #include <proto/exec.h>
  24. #include <proto/bgui.h>
  25. #include <proto/intuition.h>
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. /*
  32. **      Library base pointer.
  33. **      NOTE: The intuition.library is opened by DICE
  34. **      it's auto-init code.
  35. **/
  36. struct Library                  *BGUIBase;
  37.  
  38. /*
  39. **      Object ID's.
  40. **/
  41. #define ID_QUIT                 1
  42. #define ID_SCREENNAME           2
  43.  
  44. int main( int argc, char *argv[] )
  45. {
  46.         struct Window           *window;
  47.         Object                  *WO_Window, *GO_Quit, *GO_Name;
  48.         UBYTE                    name[ 64 ], oldname[ 64 ] = "Workbench\0";
  49.         ULONG                    signal = 0, rc, tmp;
  50.         BOOL                     running = TRUE, fallback = FALSE;
  51.  
  52.         /*
  53.         **      Open the library.
  54.         **/
  55.         if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  56.                 /*
  57.                 **      Create the window object.
  58.                 **/
  59.                 WO_Window = WindowObject,
  60.                         WINDOW_Title,           "PopWindow Demo",
  61.                         WINDOW_ScaleWidth,      20,
  62.                         WINDOW_SizeGadget,      FALSE,
  63.                         WINDOW_PubScreenName,   "Workbench",
  64.                         WINDOW_MasterGroup,
  65.                                 VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  66.                                         StartMember, GO_Name =  String( "Screen Name:", "Workbench", 64, ID_SCREENNAME ), EndMember,
  67.                                         StartMember,
  68.                                                 HGroupObject,
  69.                                                         VarSpace( 50 ),
  70.                                                         StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  71.                                                         VarSpace( 50 ),
  72.                                                 EndObject,
  73.                                         EndMember,
  74.                                 EndObject,
  75.                 EndObject;
  76.  
  77.                 /*
  78.                 **      Object created OK?
  79.                 **/
  80.                 if ( WO_Window ) {
  81.                         /*
  82.                         **      Assign a key to the button.
  83.                         **/
  84.                         tmp = GadgetKey( WO_Window, GO_Quit,  "q" );
  85.                         /*
  86.                         **      OK?
  87.                         **/
  88.                         if ( tmp ) {
  89.                                 /*
  90.                                 **      try to open the window.
  91.                                 **/
  92.                                 if ( window = WindowOpen( WO_Window )) {
  93.                                         /*
  94.                                         **      Obtain it's wait mask.
  95.                                         **/
  96.                                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  97.                                         /*
  98.                                         **      Event loop...
  99.                                         **/
  100.                                         do {
  101.                                                 Wait( signal );
  102.                                                 /*
  103.                                                 **      Handle events.
  104.                                                 **/
  105.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  106.                                                         /*
  107.                                                         **      Evaluate return code.
  108.                                                         **/
  109.                                                         switch ( rc ) {
  110.  
  111.                                                                 case    WMHI_CLOSEWINDOW:
  112.                                                                 case    ID_QUIT:
  113.                                                                         running = FALSE;
  114.                                                                         break;
  115.  
  116.                                                                 case    ID_SCREENNAME:
  117.                                                                         /*
  118.                                                                         **      Obtain screen name.
  119.                                                                         **/
  120.                                                                         GetAttr( STRINGA_TextVal, GO_Name, &tmp );
  121.                                                                         /*
  122.                                                                         **      Save it.
  123.                                                                         **/
  124.                                                                         strcpy( name, ( UBYTE * )tmp );
  125.                                                                         /*
  126.                                                                         **      Close the window.
  127.                                                                         **/
  128.                                                                         WindowClose( WO_Window );
  129.                                                                         /*
  130.                                                                         **      Setup name.
  131.                                                                         **/
  132.                                                                         openIt:
  133.                                                                         SetAttrs( WO_Window, WINDOW_PubScreenName, name, TAG_END );
  134.                                                                         /*
  135.                                                                         **      Re-open window.
  136.                                                                         **/
  137.                                                                         if ( window = WindowOpen( WO_Window )) {
  138.                                                                                 /*
  139.                                                                                 **      Re-set signal mask.
  140.                                                                                 **/
  141.                                                                                 signal = 0L;
  142.                                                                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  143.                                                                                 /*
  144.                                                                                 **      Save the name.
  145.                                                                                 **/
  146.                                                                                 strcpy( oldname, name );
  147.                                                                                 /*
  148.                                                                                 **      Show it in the gadget.
  149.                                                                                 **/
  150.                                                                                 SetGadgetAttrs(( struct Gadget * )GO_Name, window, NULL, STRINGA_TextVal, name );
  151.                                                                                 /*
  152.                                                                                 **      No fallback.
  153.                                                                                 **/
  154.                                                                                 fallback = FALSE;
  155.                                                                         } else {
  156.                                                                                 /*
  157.                                                                                 **      Failed to fallback to the
  158.                                                                                 **      previous screen?
  159.                                                                                 **/
  160.                                                                                 if ( fallback ) {
  161.                                                                                         puts( "Can't re-open the window!" );
  162.                                                                                         goto bye;
  163.                                                                                 }
  164.                                                                                 /*
  165.                                                                                 **      Re-set old name.
  166.                                                                                 **/
  167.                                                                                 SetAttrs( WO_Window, WINDOW_PubScreenName, oldname );
  168.                                                                                 /*
  169.                                                                                 **      We are falling back to the
  170.                                                                                 **      previous screen.
  171.                                                                                 **/
  172.                                                                                 fallback = TRUE;
  173.                                                                                 goto openIt;
  174.                                                                         }
  175.                                                                         break;
  176.                                                         }
  177.                                                 }
  178.                                         } while ( running );
  179.                                 } else
  180.                                         puts ( "Could not open the window" );
  181.                         } else
  182.                                 puts( "Could not assign gadget keys" );
  183.                         bye:
  184.                         /*
  185.                         **      Disposing of the window object will
  186.                         **      also close the window if it is
  187.                         **      already opened and it will dispose of
  188.                         **      all objects attached to it.
  189.                         **/
  190.                         DisposeObject( WO_Window );
  191.                 } else
  192.                         puts( "Could not create the window object" );
  193.                 CloseLibrary( BGUIBase );
  194.         } else
  195.                 puts( "Unable to open the bgui.library" );
  196.  
  197.         return( 0 );
  198. }
  199.  
  200. #ifdef _DCC
  201. int wbmain( struct WBStartup *wbs )
  202. {
  203.         return( main( 0, NULL ));
  204. }
  205. #endif
  206.